package org.javaboy.vhr.service;

import org.javaboy.vhr.mapper.EmployeeMapper;
import org.javaboy.vhr.mapper.EmployeeecMapper;
import org.javaboy.vhr.model.Employee;
import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.model.RespPageBean;
import org.javaboy.vhr.vo.EmployeeAndEc;
import org.javaboy.vhr.vo.EmployeeAndWorkid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PerEmpService {
    @Autowired
    EmployeeecMapper employeeecMapper;
    @Autowired
    EmployeeMapper employeeMapper;
    public RespPageBean getperEmpec(Integer page, Integer size){
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<Employeeec> employeeecs = employeeecMapper.getEmployeeecByPage(page,size);
        List<EmployeeAndEc> employeeAndEcs = new ArrayList<>();
        Long total = employeeecMapper.getTotal();
        for(Employeeec employeeec:employeeecs){
            EmployeeAndEc employeeAndEc = new EmployeeAndEc();
            employeeAndEc.setEmployeeec(employeeec);
            Employee employee = employeeMapper.getEmployeeById(employeeec.getEid());
            employeeAndEc.setEmployee(employee);
            employeeAndEcs.add(employeeAndEc);
        }
        RespPageBean result = new RespPageBean();
        result.setData(employeeAndEcs);
        result.setTotal(total);
        return result;
    }

    public Integer deleteEmpec(Integer ecId){return employeeecMapper.deleteByPrimaryKey(ecId);}
    public Integer addEmpec(Employeeec employeeec){
        return employeeecMapper.insertSelective(employeeec);
    }
}
